<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo">点击按钮获取您当前坐标</div>
    <button id="btn">获取</button>
    <script>
        // 手机卫星定位 lbs 
        // 陀螺仪   重力感应
        // web 应用  js -> window.localStorage
        // lbs  BOM DOM  navigator
        const demo = document.getElementById('demo')
        document.getElementById('btn').addEventListener('click', function() {
            if (navigator.geolocation) { // 浏览器嗅探
                // 不支持lbs  或关掉lbs
                console.log('---------')
                navigator.geolocation.getCurrentPosition(showPosition)
            } else {
                demo.innerHTML = '改浏览器不支持获取地理位置'
            }
        }, false) // 冒泡机制 事件从内到外
        function showPosition(position) {
            // console.log(position);
            demo.innerHTML = `维度：${position.coords.latitude} <br>
                经度：${position.coords.longitude}
            ` 
        }
    </script>
</body>
</html>